import { RootObject } from './types/rootObject';
import request from './request/request';
import requestToken from './request/requestToken';

/**
 * 用户中心接口
 */

interface TokenParams {
  code: string;
  // eslint-disable-next-line camelcase
  redirect_uri: string;
}

export const getValidateImg = () =>
  request<RootObject<any>>({
    method: 'post',
    url: '/sys-user/captcha',
  });

export const login = (data: any) =>
  request<RootObject<any>>({
    method: 'post',
    url: '/sys-user/login',
    data,
  });

export const register = (data: any) =>
  request<RootObject<any>>({
    method: 'post',
    url: '/sso/register',
    data,
  });

export const acceptToken = (params: TokenParams) =>
  request<RootObject<any>>({
    method: 'get',
    url: '/sso/getToken',
    params,
  });

export const getUserInfo = () =>
  requestToken<RootObject<any>>({
    method: 'get',
    url: '/sso/getUser',
  });

export const getUserPermission = () =>
  requestToken<RootObject<any>>({
    method: 'POST',
    url: '/sys-user/permission',
  });

export const getUserProject = () =>
  requestToken<RootObject<any>>({
    method: 'POST',
    url: '/acq-project/getList',
  });

export const removeOriginToken = () =>
  requestToken<RootObject<any>>({
    method: 'POST',
    url: '/sys-user/logout',
  });
